package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class MinimumHeightTreeLcci {
    // 2023-02-08 11:21:56
    public static void main(String[] args) {
        Solution solution = new MinimumHeightTreeLcci().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode(int x) { val = x; }
     * }
     */
    class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            int n = nums.length;
            return BuilderTree(0, n - 1, nums);
        }

        TreeNode BuilderTree(int l, int r, int[] nums) {
            if (r < l || nums == null) {
                return null;
            }
            int mid = l + (r - l + 1) / 2;
            TreeNode treeNode = new TreeNode(nums[mid]);
            treeNode.left = BuilderTree(l, mid - 1, nums);
            treeNode.right = BuilderTree(mid + 1, r, nums);
            return treeNode;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}